/*
 * Copyright 2010-2013 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package commons.util;

import java.awt.*;
import java.util.*;
import java.util.List;

import static commons.util.ExceptionUtil.throwArgEx;

/**
 * @since since
 * @version version
 * @author Susanta Tewari
 * @history Created on 8/1/13.
 */
public class ColorUtil {

    public static Map<String, Color> of_colorMap(Collection<String> labels) {
        return of_map(labels, of_colors_light());
    }

    public static Map<String, Color> of_colorMap_dark(Collection<String> labels) {
        return of_map(labels, of_colors_dark());
    }

    private static Map<String, Color> of_map(Collection<String> labels, List<Color> colors) {

        Map<String, Color> map    = new HashMap<>();
        final HashSet<String> set = new HashSet<>(labels);

        throwArgEx(labels.size() > colors.size(), "too many labels");

        final Iterator<Color> color_itr = colors.iterator();

        for (String label : set) {
            map.put(label, color_itr.next());
        }

        return map;
    }

    /**
     * Source: http://www.rapidtables.com/web/color/RGB_Color.htm
     */
    private static List<Color> of_colors_light() {

        java.util.List<Color> list = new ArrayList<>();

        list.add(Color.white);    // white
        list.add(new Color(230, 230, 250));    // lavender
        list.add(new Color(173, 216, 230));    // light blue
        list.add(new Color(135, 206, 250));    // light sky blue
        list.add(new Color(144, 238, 144));    // light green
        list.add(new Color(255, 255, 153));    // pale canary yellow
        list.add(new Color(255, 160, 122));    // light salmon
        list.add(new Color(255, 182, 193));    // light pink
        list.add(new Color(240, 255, 240));    // honeydew
        list.add(new Color(255, 239, 213));    // papya whip
        list.add(new Color(250, 240, 230));    // linen
        list.add(new Color(255, 228, 181));    // moccasin

        return list;
    }

    private static List<Color> of_colors_dark() {

        java.util.List<Color> list = new ArrayList<>();

        list.add(new Color(230, 161, 171));    // light pink
        list.add(new Color(134, 230, 134));    // light green
        list.add(new Color(171, 216, 230));    // light blue
        list.add(new Color(230, 203, 159));    // moccasin
        list.add(new Color(230, 230, 131));    // pale canary yellow

        return list;
    }
}
